// Copyright 2009 Jan Hosang <jan.hosang@gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gomake

import (
    "fmt"
    "strings"
)

type goFiles map[string] *goFile
type goFile struct {
    modTime uint64
    pkg string
    deps []string
}

func newGoFiles() (*goFiles) {
    files := make(goFiles)
    return &files
}

func (files *goFiles) extend(others *goFiles) {
    for fileName, fileObj := range *others {
        (*files)[fileName] = fileObj
    }
}

func (files *goFiles) String() (repr string) {
    elements := make([]string, len(*files))
    i := 0
    for fname, fobj := range *files {
        elements[i] = fmt.Sprintf("%s in package %s imports(%s)", fname, fobj.pkg, strings.Join(fobj.deps, " "))
        i += 1
    }
    repr = fmt.Sprintf("goFiles[%s]", strings.Join(elements, ", "))
    return
}

func newGoFile(modTime uint64) (file *goFile) {
    file = new(goFile)
    file.modTime = modTime
    return
}
